<!doctype html>
<html lang="en">
<!-- head 区域 - 开始 -->
<?php
$title='网课设置';
require_once('head.php');
if($userrow['uid']!=1){exit("<script language='javascript'>window.location.href='login.php';</script>");}
?>
<!-- head 区域 - 结束 -->

<body data-topbar="dark" data-layout="horizontal">

  <!-- 页面 - 开始 -->
  <div id="layout-wrapper">

    <!-- 头部区域 - 开始 -->
    <?php include('header.php'); ?>
    <!-- 头部区域 - 结束 -->

    <!-- 顶部导航栏 - 开始 -->
    <?php include('topnav.php'); ?>
    <!-- 顶部导航栏 - 结束 -->

    <!-- 主内容区域 - 开始 -->
    <div class="main-content" id="orderlist">

      <div class="page-content">
        <div class="container-fluid">

          <div class="row mt-4">
            <div class="col-lg-12">
              <div class="card">
                <div class="card-body">
                  <!-- 表头 - 开始 -->
                  <div class="card-button"><button style="float: right;"
                      class="btn btn-primary waves-effect waves-light" data-toggle="modal"
                      data-target="#modal-add">添加平台</button></div>
                  <h4 class="card-title">平台列表</h4>
                  <!--<p class="card-title-desc">有什么问题不懂的，首先看教程，问题解决不了，用二级域名重新搭建一套，对比找出问题，保证程序没问题，且大部分开源！！！脑筋会转弯，问题解决快</p>-->
                  <!-- 表头 - 结束 -->

                  <!-- 表体 - 开始 -->
                  <div class="table-responsive">
                    <table class="table table-hover mb-0">
                      <thead>
                        <tr>
                          <th>ID</th>
                          <th>排序</th>
                          <th>平台名称</th>
                          <th>定价</th>
                          <th>查询接口</th>
                          <th>交单接口</th>
                          <th>查询参数</th>
                          <th>对接参数</th>
                          <th>下单计算</th>
                          <th>所在分类</th>
                          <th>状态</th>
                          <th>添加时间</th>
                          <th>操作</th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr v-for="res in row.data" :key="res.cid">
                          <th scope="row">{{res.cid}}</th>
                          <td>{{res.sort}}</td>
                          <td>{{res.name}}</td>
                          <td>{{res.price}}</td>
                          <td>{{res.cx_name}}</td>
                          <td>{{res.add_name}}</td>
                          <td>{{res.getnoun}}</td>
                          <td>{{res.noun}}</td>
                          <td>{{res.yunsuan=='*'?"乘法":"加法"}}</td>
                          <td>{{res.fenlei}}</td>
                          <td><span class="badge badge-success" v-if="res.status==1">上架中</span><span
                              class="badge badge-danger" v-else-if="res.status==0">已下架</span></td>
                          <td>{{res.addtime}}</td>
                          <td><button class="btn btn-info waves-effect waves-light btn-sm" data-toggle="modal"
                              data-target="#modal-update" @click="storeInfo=res">编辑</button></td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                  <!-- 表体 - 结束 -->

                  <!-- 分页 - 开始 -->
                  <?php include('pagination.php'); ?>
                  <!-- 分页 - 结束 -->

                </div>
              </div>
            </div>
          </div>
          <!-- end row -->

        </div> <!-- container-fluid -->
      </div>
      <!-- End Page-content -->

      <!-- 修改弹窗 -->
      <div class="modal fade primary" id="modal-update">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">修改平台</h4>
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"
                  style="font-size: 30px;">&times;</span>
              </button>
            </div>

            <div class="modal-body">
              <form class="form-horizontal" id="form-update">
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="cid" :value="storeInfo.cid" />
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">排序</label>
                  <div class="col-lg-10">
                    <input type="text" name="sort" class="form-control" :value="storeInfo.sort"
                      placeholder="输入数字,商品排序从小到大">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">平台名字</label>
                  <div class="col-lg-10">
                    <input type="text" name="name" class="form-control" :value="storeInfo.name" placeholder="输入平台名字">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">定价</label>
                  <div class="col-lg-10">
                    <input type="text" name="price" class="form-control" :value="storeInfo.price" placeholder="输入价格">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">查询参数</label>
                  <div class="col-lg-10">
                    <input type="text" name="getnoun" class="form-control" :value="storeInfo.getnoun"
                      placeholder="输入标识">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">对接参数</label>
                  <div class="col-lg-10">
                    <input type="text" name="noun" class="form-control" :value="storeInfo.noun" placeholder="输入标识">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">说明</label>
                  <div class="col-lg-10">
                    <textarea name="content" class="form-control" rows="3" :value="storeInfo.content"></textarea>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">查询平台</label>
                  <div class="col-lg-10">
                    <select name="queryplat" :value="storeInfo.queryplat" class="form-control">
                      <option value="0">自营</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_huoyuan");
                        while($b=$DB->fetch($a)){	            
                        echo '<option value="'.$b['hid'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">交单平台</label>
                  <div class="col-lg-10">
                    <select name="docking" :value="storeInfo.docking" class="form-control">
                      <option value="0">自营</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_huoyuan");
                        while($b=$DB->fetch($a)){
                        echo '<option value="'.$b['hid'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">代理下单算法</label>
                  <div class="col-lg-10">
                    <select name="yunsuan" :value="storeInfo.yunsuan" class="form-control">
                      <option value="*">乘法</option>
                      <option value="+">加法</option>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">状态</label>
                  <div class="col-lg-10">
                    <select name="status" :value="storeInfo.status" class="form-control">
                      <option value="1">上架</option>
                      <option value="0">下架</option>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">分类</label>
                  <div class="col-lg-10">
                    <select name="fenlei" :value="storeInfo.fenlei" class="form-control">
                      <option value="">无</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_fenlei ORDER BY `sort` ASC");
                        while($b=$DB->fetch($a)){
                        echo '<option value="'.$b['id'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
              </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">取消</button>
              <button type="button" class="btn btn-primary waves-effect waves-light"
                @click="form('update')">确定修改</button>
            </div>
          </div>
        </div>
      </div>

      <!-- 新增弹窗 -->
      <div class="modal fade primary" id="modal-add">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">添加平台</h4>
              <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"
                  style="font-size: 30px;">&times;</span>
              </button>
            </div>

            <div class="modal-body">
              <form class="form-horizontal" id="form-add">
                <input type="hidden" name="action" value="add" />
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">排序</label>
                  <div class="col-lg-10">
                    <input type="text" name="sort" class="form-control" placeholder="输入数字,不填默认10,商品排序从小到大">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">平台名字</label>
                  <div class="col-lg-10">
                    <input type="text" name="name" class="form-control" placeholder="输入平台名字">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">定价</label>
                  <div class="col-lg-10">
                    <input type="text" name="price" class="form-control" placeholder="输入价格">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">查询参数</label>
                  <div class="col-lg-10">
                    <input type="text" name="getnoun" class="form-control" placeholder="输入标识">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">对接参数</label>
                  <div class="col-lg-10">
                    <input type="text" name="noun" class="form-control" placeholder="输入标识">
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">说明</label>
                  <div class="col-lg-10">
                    <textarea name="content" class="form-control" rows="3"></textarea>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">查询平台</label>
                  <div class="col-lg-10">
                    <select name="queryplat" class="form-control">
                      <option value="0">自营</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_huoyuan");
                        while($b=$DB->fetch($a)){
                        echo '<option value="'.$b['hid'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">对接平台</label>
                  <div class="col-lg-10">
                    <select name="docking" class="form-control">
                      <option value="0">自营</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_huoyuan");
                        while($b=$DB->fetch($a)){
                        echo '<option value="'.$b['hid'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">状态</label>
                  <div class="col-lg-10">
                    <select name="status" class="form-control">
                      <option value="1">上架</option>
                      <option value="0">下架</option>
                    </select>
                  </div>
                </div>
                <div class="form-group row">
                  <label class="col-lg-2 col-form-label">分类</label>
                  <div class="col-lg-10">
                    <select name="fenlei" class="form-control">
                      <option value="">无</option>
                      <?php
                        $a=$DB->query("select * from qingka_wangke_fenlei ORDER BY `sort` ASC");
                        while($b=$DB->fetch($a)){
                        echo '<option value="'.$b['id'].'">'.$b['name'].'</option>';	
                        }
                      ?>
                    </select>
                  </div>
                </div>
              </form>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary waves-effect waves-light"
                  @click="form('add')">确定添加</button>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 底部版权区域 - 开始 -->
      <?php include('copyright.php'); ?>
      <!-- 底部版权区域 - 结束 -->

    </div>
    <!-- 主内容区域 - 结束 -->
  </div>
  <!-- 页面 - 结束 -->

  <!-- 底部文件 - 开始 -->
  <?php include('footer.php'); ?>
  <!-- 底部文件 - 结束 -->

  <script type="text/javascript">
    new Vue({
      el: "#orderlist",
      data: {
        row: null,
        storeInfo: {}
      },
      methods: {
        get: function (page) {
          // var load=layer.load(2);
          SlickLoader.setText('加载中...')
          SlickLoader.enable();
          this.$http.post("/apisub.php?act=classlist", { page: page }, { emulateJSON: true }).then(function (data) {
            // layer.close(load);
            SlickLoader.disable();
            if (data.data.code == 1) {
              this.row = data.body;
            } else {
              layer.msg(data.data.msg, { icon: 2 });
            }
          });
        },
        form: function (form) {
          // var load=layer.load(2);
          SlickLoader.setText('加载中...')
          SlickLoader.enable();
          this.$http.post("/apisub.php?act=upclass", { data: $("#form-" + form).serialize() }, { emulateJSON: true }).then(function (data) {
            // layer.close(load);
            SlickLoader.disable();
            console.log($("#form-" + form).serialize())
            if (data.data.code == 1) {
              this.get(this.row.current_page);
              $("#modal-" + form).modal('hide');
              layer.msg(data.data.msg, { icon: 1 });
              // 清空表单
              document.getElementById("form-add").reset();
            } else {
              layer.msg(data.data.msg, { icon: 2 });
            }
          });
        },
        bs: function (oid) {
          layer.msg(oid);
        }
      },
      mounted() {
        this.get(1);
      }
    });
  </script>

</body>

</html>